var plane_lat, plane_lon, plane_alt, plane_roll, plane_pitch, plane_heading, plane_course, plane_bat, plane_speed, plane_speed_method, plane_alt_method;
var plane_gps_valid, plane_gps_pdop, plane_gps_vs, plane_gps_vs_prn, plane_gps_vs_elev, plane_gps_vs_azi, plane_gps_vs_snr;
var plane_ap_en, plane_ap_lat, plane_ap_lon, plane_ap_alt;
var plane_last_signal;

var groundLevel = 0;

plane_lat = 33.004591;
plane_lon = -117.135056;
plane_alt = null;
plane_roll = null;
plane_pitch = null;
plane_heading = null;
plane_course = null;
plane_bat = null;
plane_speed = null;
plane_speed_method = "GPS";
plane_alt_method = "GPS";
plane_ap_en = false;
plane_ap_lat = 0;
plane_ap_lon = 0;

gps_status = 0;
gps_lat = 0;
gps_lon = 0;
gps_alt = 0;
gps_speed = 0;
gps_hdop = 0;
gps_vdop = 0;
gps_pdop = 0;
gps_course = 0;
gps_deviation = 0;
gps_vsat = new Array();
gps_vsat_count = 0;

//setInterval("plane_course=(plane_course+5.3)%360;plane_speed+=0.1;plane_alt+=1;",500);
//setInterval("plane_alt+=0.3",100);

setInterval("_tcpLoop()",100);

function _tcpLoop()
{
	try
	{
		$(document).ready(function(){
			$.ajax({
				type: "GET",
				url: "http://localhost:8080/at_telem",
				dataType: "xml",
				success: function(xml) {
					//alert("YAY");
					plane_lat = ff($(xml).find("lat").text());
					plane_lon = ff($(xml).find("lon").text());
					plane_alt = ff($(xml).find("alt").text());
					plane_roll = ff($(xml).find("roll").text());
					plane_pitch = ff($(xml).find("pitch").text());
					plane_heading = ff($(xml).find("heading").text());
					plane_speed = ff($(xml).find("speed").text());
					plane_ap_en = $(xml).find("ap").text()=="True";
				}
			});//AJAX
		});//DOCUMENT READY
	}catch (e){alert("TCP LOOP IN AIRCRAFT: "+e);}
}

function ff(input)
{
	if (input=="None"){return null;}
	return parseFloat(input);
}

